<?php
class MoneyController extends Controller
{

	public  function actionFillup()
	{
             $user= new User();
              
            if(isset($_POST['out_summ']))
            {
                $out_summ=$_POST['out_summ'];
                $mrh_login = "i-stud.ru"; // your login here
                $mrh_pass1 = "kolvzad13665"; // merchant pass1 here 
                $inv_id = Yii::app()->user->getId(); // shop's invoice number // (unique for shop's lifetime)
                $inv_desc = "desc"; // invoice desc
               // $out_summ = "5.12"; // invoice summ // build CRC value
                $crc = md5("$mrh_login:$out_summ:$inv_id:$mrh_pass1"); // build URL
//                $url = "https://merchant.roboxchange.com/Index.aspx?MrchLogin=$mrh_login&". "OutSum=$out_summ&InvId=$inv_id&Desc=$inv_desc&SignatureValue=$crc"; // print URL if you need
//                echo "<a href='$url'>Payment link</a>";
                $this->redirect('http://test.robokassa.ru/Index.aspx?MrchLogin='.$mrh_login.'&OutSum='.$out_summ.'&InvId='.$inv_id.'&Desc='.$inv_desc.'&SignatureValue='.$crc.'');
            }
               
		$Info=user::model()->with('user_info')->findByPk(Yii::app()->user->getId());
		$this->render('fillup',array('info'=>$Info));
	}

        function actionSuccess()
        {
            // as a part of SuccessURL script // your registration data
            $mrh_pass1 = "kolvzad13665"; // merchant pass1 here // HTTP parameters:
            $out_summ = $_REQUEST["OutSum"];
            $inv_id = $_REQUEST["InvId"];
           
            $crc = $_REQUEST["SignatureValue"];
            $crc = strtoupper($crc); // force uppercase // build own CRC
            $my_crc = strtoupper(md5("$out_summ:$inv_id:$mrh_pass1"));
            if (strtoupper($my_crc) != strtoupper($crc))
                {
                echo "bad sign\n"; exit();
                } // you can check here, that resultURL was called // (for better security) // OK, payment proceeds
                 
                $user_inf=User::model()->findByPk($inv_id);
                $schet=$user_inf->schet+$out_summ;
                $user_inf->schet=$schet;
                $user_inf->save();
                echo "Thank you for using our service ".$user_inf->username;
        }

        function actionFail()
        {

        }
        function actionResult()
        {
            $mrh_pass2 = "kolvzad13665"; // merchant pass2 here // HTTP parameters:
            $out_summ = $_REQUEST["OutSum"];
            $inv_id = $_REQUEST["InvId"];
            $crc = $_REQUEST["SignatureValue"]; // HTTP parameters: $out_summ, $inv_id, $crc
            $crc = strtoupper($crc); // force uppercase // build own CRC
            $my_crc = strtoupper(md5("$out_summ:$inv_id:$mrh_pass2"));
            if (strtoupper($my_crc) != strtoupper($crc))
                {
                echo "bad sign\n"; exit();
                } // print OK signature
                echo "OK$inv_id\n";
        }


}

?>
